template<typename T>
class Singleton {
public:
    static T &GetInstance() {
        static T instance;
        return instance;
    }

protected:
    // 让子类能够访问到该类的构造和析构函数
    Singleton() = default;
    ~Singleton() = default;

private:
    // 禁用拷贝和移动
    Singleton(const Singleton &) = default;
    Singleton &operator=(const Singleton &) = default;
    Singleton(Singleton &&) noexcept = default;
    Singleton &operator=(Singleton &&) noexcept = default;
};

class A : public Singleton<A> {
public:
    ~A() = default;

private:
    A() = default;  //禁止外部构造该类
    friend class Singleton<A>; //但允许Singleton<A>构造该类
};

int main() {
    A &a = A::GetInstance();
}